var SatisfactionSurveyTable = {
    id: "SatisfactionSurveyTable",
    seItem: null,
    table: null,
    layerIndex: -1
};

// 定义表头字段
SatisfactionSurveyTable.initColumn = function () {
    var columns = [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: 'customerId', field: 'customerId', visible: false, align: 'center', valign: 'middle'},
        {title: 'reservationsId', field: 'reservationsId', visible: false, align: 'center', valign: 'middle'},
        {
            title: '患者姓名', field: 'customerName', align: 'center', valign: 'middle', width: 120,
            formatter: function (value, row, index) {
                return "<a href='javascript:;' onclick='SatisfactionSurveyTable.openBilee(" + '"' + row.reservationsId + '"' + ")' style='display: flex;align-items: center;'><span class='portraitHeadName'>" + value + "</span></a>"
            }
        },
        {title: '联系电话', field: 'customerPhone', align: 'center', valign: 'middle', sortable: true ,width: 140},
        {title: '就诊门诊', field: 'simplename', align: 'center', valign: 'middle', sortable: true ,width: 140},
        {title: '医生', field: 'doctor', align: 'center', valign: 'middle', sortable: true ,width: 140},
        {title: '项目', field: 'department', align: 'center', valign: 'middle', sortable: true ,width: 140},
        {title: '星数', field: 'starlevel', align: 'center', valign: 'middle', sortable: true ,width: 100},
        {title: '评语', field: 'proposal', align: 'center', valign: 'middle', sortable: true},
        {title: '服务质量', field: 'evaluationOneList', align: 'center', valign: 'middle', sortable: true},
        {title: '项目质量', field: 'evaluationTwoList', align: 'center', valign: 'middle', sortable: true},
        {title: '评价时间', field: 'addTime', align: 'center', valign: 'middle', sortable: true ,width: 170}
    ];
    return columns
};

SatisfactionSurveyTable.openBilee = function (reservationsId) {//点击姓名查看详情
    var index = layer.open({
        type: 2,
        title: '病历',
        area: ['100%', '100%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/satisfactionSurvey/getCaseInfo/' + reservationsId
    });
    this.layerIndex = index;
};

// 判断是否选中
SatisfactionSurveyTable.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false
    } else {
        SatisfactionSurveyTable.seItem = selected[0];
        return true
    }
};

// 表格数据传参
SatisfactionSurveyTable.formParams = function () {
    var queryData = {};
    queryData['reach'] = $("#guestDimensionPublic", parent.document).val();
    queryData['outpatientName'] = multipleSelection($('#outpatientName').val());
    queryData['startTime'] = $("#startTime").val();
    queryData['endTime'] = $("#endTime").val();
    return queryData
};

// 条件重置初始化
SatisfactionSurveyTable.resetSearch = function () {
    $("#guestDimensionPublic", parent.document).val("");
    $("#outpatientName").selectpicker('deselectAll');
    $("#startTime").val(setDateTime(new Date(), 0) + " 00:00:00");
    $("#endTime").val(setDateTime(new Date(), 0) + " 23:59:59");
    SatisfactionSurveyTable.search();
};

// 刷新页面
SatisfactionSurveyTable.search = function () {
    SatisfactionSurveyTable.table.refresh({query: SatisfactionSurveyTable.formParams()});
};

// 初始化时间
SatisfactionSurveyTable.naturalDaySearch = function () {
    $("#startTime").val(setDateTime(new Date(), 0) + " 00:00:00");
    $("#endTime").val(setDateTime(new Date(), 0) + " 23:59:59");
    SatisfactionSurveyTable.search();
};


$(function () {
    var defaultColunms = SatisfactionSurveyTable.initColumn();
    var table = new BSTable(SatisfactionSurveyTable.id, "/satisfactionSurvey/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(SatisfactionSurveyTable.formParams());
    SatisfactionSurveyTable.table = table.init();
    SatisfactionSurveyTable.naturalDaySearch();
});

// 点击最上方搜索按钮根据条件赛选表格
$("#guestDimensionSearchAll", parent.document).click(function () {
    SatisfactionSurveyTable.search();
});

// 时间回调函数 - 刷新表格
checkDate = function () {
    SatisfactionSurveyTable.search();
};